/*
 * Sensor.java
 *
 * Created on May 6, 2007, 2:02 PM
 *
 */

package sbc.fabrik.model;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import sbc.fabrik.model.Employee;

/**
 *
 * @author lazafi
 */
public class Sensor implements java.io.Serializable {
    
    private String sid;
    private final EnumMap<Feature, Employee> features;
    
    public Sensor() {
        features = new EnumMap<Feature, Employee>(Feature.class);
    }
    
    public Sensor(String sid) {
        this();
        this.sid = sid;
    }
    
    
    public ArrayList<Feature> getFeatures() throws Exception{
        ArrayList<Feature> featuresList = new ArrayList<Feature>();
        for (Feature f: features.keySet()) {
            featuresList.add(f);
        }
        return featuresList;
    }
    
    public EnumMap<Feature, Employee> getFeaturesEmployees() throws Exception{
        return new EnumMap<Feature, Employee>(features);
    }
    
    public void inspect(Feature f, Employee e) {
        if (features.containsKey(f))
            features.put(f, e);
        else
            System.out.println("Sensor: Feature <" + f.name() + "> not Supported!");
    }
    
    
    public String getSid() {
        return sid;
    }
    
    public void setSid(String sid) {
        this.sid = sid;
    }
    
    public String toString() {
        String retValue = "";
        try {
            retValue = "Sensor" + " " + "{" + sid + "} ";
            for (Feature f : getFeatures()) {
                
                
                int eId = (features.get(f) != null) ? (features.get(f).getId()) : (-1);
                
                retValue = retValue.concat("(" + f.getLabel() + ")" + "[" +  eId  + "] ");
                
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return retValue;
    }
    
    public void addFeature(Feature feature) {
        //System.err.println("this.features.size() = " + this.features.size() );
        if (this.features.size() < 3) {
            this.features.put(feature, null);
        }
        //printFeatures();
    };
    
    private void printFeatures() {
        int i = 0;
        for (Feature f: features.keySet()) {
            System.out.println((i++) + "-" + f.getLabel());
        }
    };
    
}
